//
//  YLMusicView.m
//  音乐播放器
//
//  Created by 袁量 on 2017/6/6.
//  Copyright © 2017年 袁量. All rights reserved.
//

#import "YLMusicView.h"
#import "Masonry.h"
#import "YLMusicTool.h"
@interface YLMusicView ()<UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation YLMusicView

- (instancetype)initWithCoder:(NSCoder *)coder
{
    printf("initWithaCoder");
    self = [super initWithCoder:coder];
    if (self) {
        self.backgroundColor = [UIColor redColor];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    printf("initWithFrame");
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setupTableView];
    }
    return self;
}
#pragma mark - 初始化TableView
- (void)setupTableView
{
    // 1.初始化
    _tableView = [[UITableView alloc] init];
    [self addSubview:_tableView];
//    self.tableView = tableView;
//    self.tableView.backgroundColor = [UIColor whiteColor];
    // 2.设置数据源
    self.tableView.dataSource = self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    // 1.添加约束
    self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.mas_bottom);
        make.height.equalTo(self.mas_height);
        make.right.equalTo(self.mas_right);
//        make.left.equalTo(self.mas_left).offset(self.bounds.size.width);
//        make.width.equalTo(self.mas_width);
    }];
    
    // 2.改变tableView属性
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 40;
    self.tableView.contentInset = UIEdgeInsetsMake(self.tableView.bounds.size.height * 0.5, 0, self.tableView.bounds.size.height * 0.5, 0);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    printf("返回行数");
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    printf("返回歌名");
    static NSString *ID = @"cell";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.backgroundColor = [UIColor blueColor];
    NSLog(@"%@",[[YLMusicTool musics] objectAtIndex:indexPath.row]);
    cell.textLabel.text = [[YLMusicTool musics] objectAtIndex:indexPath.row];
    return cell;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
